package com.init.demo.controller.system;

import com.init.demo.controller.BaseController;
import com.init.demo.entity.system.SystemLog;
import com.init.demo.service.system.SystemLogService;
import com.init.demo.utils.PageRequestUtil;
import com.init.demo.utils.PagingResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/systemLog")
public class SystemLogController extends BaseController {

    @Autowired
    private PageRequestUtil pageRequestUtil;

    @Autowired
    private SystemLogService systemLogService;

    @GetMapping(value = "/log")
    public String log() {
        return "system/logManager";
    }

    @ResponseBody
    @GetMapping(value = "/findAllLog")
    public PagingResult<SystemLog> findAllLog(@RequestParam Map<String, Object> params) {
        Map map = getMap(params);
        map.put("sorter", "createTime_descend"); //登录日期倒叙排列
        Map advQuery = (Map) map.get("advQuery");
        PageRequest pageRequest = pageRequestUtil.genericPageRequestByRequest(map);
        return systemLogService.findAllLog(pageRequest, advQuery, "");
    }
}
